package com.pucheng.bracelet.ui.activity

import android.os.Bundle
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.base.BaseTitleActivity
import com.pucheng.bracelet.app.util.CacheUtil
import com.pucheng.bracelet.databinding.ActivityFlagBinding
import com.pucheng.bracelet.viewmodel.FlagViewModel
import kotlinx.android.synthetic.main.activity_flag.*

class FlagActivity : BaseTitleActivity<FlagViewModel, ActivityFlagBinding>() {
    override fun layoutId(): Int = R.layout.activity_flag
    override fun titleText(): String = getString(R.string.set_flag)

    private  var stepsData:String = CacheUtil.getStepsFlag()

    override fun initView(savedInstanceState: Bundle?) {
        val stepFlagDatas = mutableListOf<String>()
        val stepFlag = CacheUtil.getStepsFlag()
        var selectIndex :Int = 0
        for (index in 4..35) {
            if (stepFlag.toInt() == index * 1000){
                selectIndex = index-4
            }
            stepFlagDatas.add((index * 1000).toString())
        }
        wp_steps_flag.adapter = ArrayWheelAdapter(stepFlagDatas)
        wp_steps_flag.currentItem = selectIndex
        wp_steps_flag.setOnItemSelectedListener { index ->
            stepsData = stepFlagDatas[index]
        }
    }

    override fun onPause() {
        super.onPause()
        CacheUtil.setStepsFlag(stepsData)
        mViewModel.setStepsFlag(stepsData.toInt())
        appViewModel.stepsFlag.value = stepsData
    }

}